home *** CD-ROM | disk | FTP | other *** search
- Path: peer-news.britain.eu.net!strath-cs!st-and!usenet
- From: Peter Foldiak <Peter.Foldiak@st-andrews.ac.uk>
- Newsgroups: comp.lang.c++
- Subject: HELP! error(3328)"class template .. has already been defined" when using multiple files
- Date: Sun, 10 Mar 1996 23:33:28 +0000
- Organization: University of St. Andrews
- Message-ID: <314366C8.2F1C@st-andrews.ac.uk>
- NNTP-Posting-Host: banana.st-and.ac.uk
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (X11; I; IRIX 5.3 IP22)
-
- I would like to ask for some help with the following problem.
- (I tried to simplify the files as much as possible).
- When I try to compile the files below on a SG Indy I get the
- following error:
-
- ----
- % CC main.c list.c
- main.c:
- "list.h", line 1: error(3328): class template "list" has already been
- defined
- template<class T> class list {
- ^
- 1 error detected in the compilation of "main.c".
- list.c:
- %
- ----
-
- If I concatenate list.c and main.c into a file called listmain.c,
- and compile with
- % CC listmain.c
- %
- the error message disapprears! So I guess it has something to do
- with the bits being in separate files.
- Also, if the files contain no templates there is no error.
- Could anyone please help? Any ideas?
- Is there something special with including headrers when I use templates?
- Thanks!
-
- Peter
- -
-
- ===========================================
- The files that won't compile:
-
- list.h:
- -------
- template<class T> class list {
- T x;
- list *next;
- public:
- list<T>::list();
- };
-
- list.c:
- -------
- #include <stdio.h>
- #include "list.h"
- template<class T> list<T>::list()
- {
- next = NULL;
- }
-
- main.c:
- -------
- #include "list.h"
- int main()
- {
- list<int> q;
- return 0;
- }
-
-
- =======================================
- This file compiles without error:
- listmain.c:
- -----------
- #include <stdio.h>
- #include "list.h"
-
- template<class T> list<T>::list()
- {
- next = NULL;
- }
-
- int main()
- {
- list<int> q;
- return 0;
- }
-
- --
- Peter Foldiak http://psych.st-and.ac.uk:8080/~pf2
- Psychological Laboratory phone: +44 1334 462087
- University of St Andrews fax: +44 1334 463042
- St Andrews KY16 9JU, U.K. e-mail: Peter.Foldiak@st-and.ac.uk
-